/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.tb_certificate_vehicles.service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.modules.tb_certificate_vehicles.dao.TbCertificateVehiclesDao;
import com.thinkgem.jeesite.modules.tb_certificate_vehicles.entity.TbCertificateVehicles;

/**
 * 车辆证件审核时间表Service
 * @author ZhaoHai
 * @version 2017-07-06
 */
@Service
@Transactional(readOnly = true)
public class TbCertificateVehiclesService extends CrudService<TbCertificateVehiclesDao, TbCertificateVehicles> {

	public TbCertificateVehicles get(String id) {
		return super.get(id);
	}
	
	public List<TbCertificateVehicles> findList(TbCertificateVehicles tbCertificateVehicles) {
		return super.findList(tbCertificateVehicles);
	}
	
	public Page<TbCertificateVehicles> findPage(Page<TbCertificateVehicles> page, TbCertificateVehicles tbCertificateVehicles) {
		return super.findPage(page, tbCertificateVehicles);
	}
	
	@Transactional(readOnly = false)
	public void save(TbCertificateVehicles tbCertificateVehicles) {
		super.save(tbCertificateVehicles);
	}
	
	@Transactional(readOnly = false)
	public void delete(TbCertificateVehicles tbCertificateVehicles) {
		super.delete(tbCertificateVehicles);
	}
	/**
	 * 查询证件检测日期小于 倒计时天数的证件和车辆信息
	 * @return ArrayList<TbCertificateVehicles>
	 */
	public ArrayList<Map<String,String>> certificatesalarm(){
		ArrayList<Map<String,String>> list = new ArrayList<Map<String,String>>();
		
		 SimpleDateFormat sdf =   new SimpleDateFormat( "yyyy-MM-dd" );
		 String carNum=null; //车辆的编号
		 String certificatesDate; //证件检验日期
		 String dataType=null; //证件类型
		 String timedifferences=null;  //证件检验日期与当前日期的天数差
		 String carCode=null;   //车辆车牌号
		 ArrayList<TbCertificateVehicles> certificatesalarm = dao.certificatesalarm();
		for (TbCertificateVehicles tbCertificateVehicles : certificatesalarm) {
			Map<String,String> map = new HashMap<String,String>();
			carNum=tbCertificateVehicles.getCarNum();
			certificatesDate=sdf.format(tbCertificateVehicles.getCertificatesDate());
			dataType=tbCertificateVehicles.getDataType();
			if(dataType.contains("1")){
				dataType="运营证审核日期";
			}
			else if(dataType.contains("2")){
				dataType="行驶证审核日期";
			}
			else if(dataType.contains("3")){
				dataType="罐体检验日期";
			}
			else if(dataType.contains("4")){
				dataType="GPS检验日期";
			}
			else if(dataType.contains("5")){
				dataType="交强险上保日期";
			}
			else if(dataType.contains("6")){
				dataType="商业险上保日期";
			}
			else if(dataType.contains("8")){
				dataType="承运险上保日期";
			}
			else if(dataType.contains("9")){
				dataType="评定表";
			}else if(dataType.contains("10")){
				dataType="顶灯更换日期";
			}
			timedifferences=(tbCertificateVehicles.getTimedifferences())+"";
			carCode=tbCertificateVehicles.getCarCode();
			map.put("carNum", carNum);
			map.put("carCode",carCode);
			map.put("dataType", dataType);
			map.put("timedifferences", timedifferences);
			map.put("certificatesDate", certificatesDate);
			list.add(map);
			}
		return list;					
	}
}